<?php
namespace Api\Controller;
use Think\Controller;
class PostController extends Controller {

    /*帖子列表  开发人：周弈男*/
    public function allpost(){
       $post=M('post');
       $post=$post->join('user ON user.userid = post.userid')->field('postid,post,time,postpic,ordernum,username,pic')->select();
       if($post==null){
          $this->ajaxReturn($post);
       }else{
          $this->ajaxReturn($post);
       }
    }
    /*帖子评论  开发人：周弈男*/
    public function getcomment (){
       $postid=$_GET['postid'];
       $comment=M('comment');
       $comment=$comment->where("postid=$postid")->join('user ON user.userid = comment.user')->field('commentid,username,content,postid,time')->select();
       var_dump($comment);
       die;
       if($comment==null){
          $this->ajaxReturn($comment);
       }else{
          $this->ajaxReturn($comment);
       }
    }
    /*评论帖子  开发人：周弈男*/
    public function comment (){
       $userid=$_GET['userid'];
       $content=$_GET['content'];
       $postid=$_GET['postid'];
       $comment=M('comment');
       $data['user']=trim($userid);
       $data['content']=trim($content);
       $data['postid']=trim($postid);
       $data['time']=date('Y-m-d H:i:s');
       $comment=$comment->add($data);
       if($comment!==false){
          $re['success']='1';
          $this->ajaxReturn($re);
       }else{
          $re['success']='0';
          $this->ajaxReturn($re);
       }
    }

}